<template>
	<el-container>
		<el-aside width="200px" v-loading="showGrouploading">
			<el-container>
				<el-header>
					<el-input placeholder="输入关键字进行过滤" v-model="groupFilterText" clearable></el-input>
				</el-header>
				<el-main class="nopadding">
					<el-tree ref="sortDialog" class="menu" node-key="sortId" :data="sortDialogList" :props="groupsProps" :current-node-key="''" :highlight-current="true" :expand-on-click-node="false"
							 :filter-node-method="groupFilterNode" @node-click="groupClick">
						<template #default="{node, data}">
							<span class="custom-tree-node">
								<span class="label">{{ node.label }}</span>
								<span class="code">{{ data.code }}</span>
							</span>
						</template>
					</el-tree>
				</el-main>
			</el-container>
		</el-aside>
		<el-container>
			<el-header style="height: auto;">
				<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
			</el-header>
			<el-header>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.keyword" placeholder="报表名称"></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" row-key="recordId" stripe remoteSort remoteFilter>
					<el-table-column label="#" type="index" width="50"></el-table-column>
					<el-table-column label="报表名称" prop="title" width="200" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="报表分类" prop="manageTitle" width="200" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="版本" prop="version" width="150"></el-table-column>
					<el-table-column label="创建时间" prop="createTime" width="150"></el-table-column>
					<el-table-column label="当前状态" prop="status" width="100">
					</el-table-column>
					<el-table-column label="操作" fixed="right" align="right" width="120">
						<template #default="scope">
							<el-button-group>
								<el-button text type="primary" size="small" @click="downExcelReport(scope.row, scope.$index)">下载</el-button>
								<el-button text type="primary" size="small" @click="showExcelReport(scope.row, scope.$index)">查看</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
</template>
<script>
import scSelectFilter from '@/components/scSelectFilter'
export default {
	name: 'Excel Record Search',
	components: {
		scSelectFilter
	},
	data() {
		return {
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "报表模版",
					key: "manageId",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				}],
			showGrouploading: false,
			groupFilterText: '',
			templateList: [],
			sortDialogList: [],
			groupsProps: {
				label: "name",
				value: "sortId"
			},
			apiObj:this.$API.bi.excel.getBiExcelDataList,
			biExcelSort: '',
			search: {
				date: '',
				manageId:'',
				keyword:null
			}
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.sortDialog.filter(val);
		}
	},
	mounted() {
		this.getBiExcelSortTree();
		this.getMyBiExcelManageForSelect();
	},
	methods: {
		//加载树数据
		async getBiExcelSortTree() {
			this.showGrouploading = true;
			var res = await this.$API.bi.excel.getBiExcelSortTree.get();
			this.showGrouploading = false;
			this.sortDialogList = res.data;
		},
		async getMyBiExcelManageForSelect() {
			var res = await this.$API.bi.excel.getMyBiExcelManageForSelect.get({biExcelSort: this.biExcelSort});
			if (res.code == '200') {
				let params={options:[{
						label: "全部",
						value: ""
					}]};
				this.filterData[1].options=params.options.concat(res.data);
			}
		},
		filterChange(data){
			this.search.date = data.date;
			this.search.manageId = data.manageId;
			this.$refs.table.upData(this.search)
		},
		//树过滤
		groupFilterNode(value, data) {
			if (!value) return true;
			return data.sortName.indexOf(value) !== -1;
		},
		//树点击事件
		groupClick(data) {
			this.biExcelSort = data.sortId
			this.getMyBiExcelManageForSelect();
		},
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//下载
		downExcelReport(row) {
			this.$API.bi.excel.downExcelReport.fileDownload({recordId:row.recordId});
		},
		//删除
		async showExcelReport(row) {
			window.open("/#/bi/excel/search/fillexcel?recordId="+row.recordId+"&ddtab=true")
		},
	}
}
</script>
<style scoped>
.custom-tree-node {
	display: flex;
	flex: 1;
	align-items: center;
	justify-content: space-between;
	font-size: 14px;
	padding-right: 24px;
	height: 100%;
}

.custom-tree-node .code {
	font-size: 12px;
	color: #999;
}

.custom-tree-node .do {
	margin-left: 10px;
	display: none;
}

.custom-tree-node:hover .code {
	display: none;
}

.custom-tree-node:hover .do {
	margin-left: 10px;
	display: inline-block;
}

.el-card {
	margin-bottom: 15px;
}

.code-item {
	cursor: pointer;
}

.code-item .img {
	width: 100%;
	height: 100px;
	background: linear-gradient(to right, #409eff, #f56c6c);
	display: flex;
	align-items: center;
	justify-content: center;
}

.code-item .img i {
	font-size: 100px;
	color: #fff;
	background-image: -webkit-linear-gradient(top left, #fff, #09f 100px);
	-webkit-background-clip: text;
	-webkit-text-fill-color: transparent;
}

.code-item .title {
	padding: 5px;
	display: flex;
}

.code-item .title h4 {
	font-size: 12px;
	color: #999;
	font-weight: normal;
	margin-top: 5px;
}
</style>
